package haoi.dt;

import haoi.dt.impl.ImageServiceImpl;
import haoi.dt.utils.SequenceUtil;

import java.util.HashMap;
import java.util.Map;

public class MainTest {
    public static dt.ImageService imageService;


    public static void main (String args[]){

        String responseStr = sendFile("c:\\1.png");

        getAnswer(responseStr);
//		sendError(responseStr);
        getPoint();

    }
    /**
     * 上传图片(Base64版)
     * {Host}/UploadBase64.aspx
     * @param paramMap
     * @param imagePath //"d:\\test\\captcha.jpg"
     * @return
     */
    public static String sendFile(String filePath){
        Map<String, Object> parameterMap = new HashMap<String, Object>();
        parameterMap.put("UserStr", "win178|ED52AB2B427A98A5");
        parameterMap.put("GameID", "1004"); //题目编号，在好爱首页获取
        parameterMap.put("TimeOut", "600"); //超时时间 单位秒
//        parameterMap.put("Rebate", "win178|ED52AB2B427A98A5");  //作者SOFTKEY
        parameterMap.put("Kou", "0");	//自定义扣分，一般写0
        parameterMap.put("BeiZhu", "");	//备注内容，会显示给好爱的员工
        parameterMap.put("Key", SequenceUtil.getTenRandom());//随机数
        imageService = new ImageServiceImpl();
        //String responseStr = imageService.sendFile(parameterMap,"C:\\Users\\fushiyong\\Desktop\\1.png");
        String responseStr = imageService.sendFile(parameterMap,filePath);
        //验证码文件
//        System.out.println(responseStr);
        return responseStr;
    }
    /**
     * 获取答案（发送题目后内部函数会循环每秒调用一次获取答案，直至返回值不为空字符串""，结束整个发题函数
     * {Host}/GetAnswer.aspx
     * ID=5001_12_241659339E7D986521&r=94aswz2w7qz
     * @param paramMap
     * @return
     */
    public static String getAnswer(String id){
        Map<String, Object> parameterMap = new HashMap<String, Object>();
        parameterMap.put("ID", id);	//题目流水号
        parameterMap.put("r", SequenceUtil.getSeqByRandom());	//随机数
        imageService = new ImageServiceImpl();
        String responseStr = imageService.getAnswer(parameterMap);
//        System.out.println(responseStr);
        return responseStr;
    }
    /**
     * 申诉题目 TID一定要先判断是否正确，再传入。（异常返回值要么带#、要么是""）
     * {Host}/SendError.aspx
     * ID=5001_12_241659339E7D986521&r=94aswz2w7qz
     * @param paramMap
     * @return
     */
    public static String sendError(String id){
        Map<String, Object> parameterMap = new HashMap<String, Object>();
        parameterMap.put("ID", id);	//题目流水号
        parameterMap.put("r", SequenceUtil.getSeqByRandom());	//随机数
        imageService = new ImageServiceImpl();
        String responseStr = imageService.sendError(parameterMap);
        System.out.println(responseStr);
        return responseStr;
    }
    /**
     * 获取题分【切记不要频繁调用】
     * {Host}/ GetPoint.aspx
     * User=abcde|241659339E7D986521&r=243wzxaw7qz
     * @param paramMap
     * @return
     */
    public static String getPoint(){
        Map<String, Object> parameterMap = new HashMap<String, Object>();
        parameterMap.put("User", "win178|ED52AB2B427A98A5");
        parameterMap.put("r", SequenceUtil.getSeqByRandom());	//随机数
        imageService = new ImageServiceImpl();
        String responseStr = imageService.getPoint(parameterMap);
        System.out.println(responseStr);
        return responseStr;
    }
}
